<template>
  <el-dialog :title="title" :visible="visible" @close="close">
    <el-form
      ref="form"
      :model="entityData"
      :rules="rules"
      label-width="80px"
      label-position="right"
      style="width:90%;margin:0px auto;"
    >
      <!--表单区域 -->
      <el-form-item label="名称" prop="name">
        <el-input v-model="entityData.name" :readonly="readonly" />
      </el-form-item>
      <el-form-item label="类名" prop="jobClass">
        <el-input v-model="entityData.jobClass" :readonly="readonly" />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="entityData.remark" :readonly="readonly" />
      </el-form-item>
      <el-form-item label="排序号" prop="orderNo">
        <el-input v-model="entityData.orderNo" :readonly="readonly" />
      </el-form-item>
      <el-form-item label="任务参数">
        <div style="margin-top:10px;">
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="small"
            style="float:right;"
            @click="addParam"
          >新增</el-button>
          <div class="clearfix" />
          <el-table
            :data="entityData.paramList"
            highlight-current-row
            style="margin-top:5px;"
            border
            width="580px"
          >
            <el-table-column type="index" label="序号" width="50" />
            <el-table-column width="160px">
              <template slot="header">
                <span style="color:red;">*</span>
                编码
              </template>
              <template slot-scope="scope">
                <el-input v-model="scope.row.paramCode" />
              </template>
            </el-table-column>
            <el-table-column>
              <template slot="header">默认值</template>
              <template slot-scope="scope">
                <el-input v-model="scope.row.paramValue" />
              </template>
            </el-table-column>
            <el-table-column>
              <template slot="header">描述</template>
              <template slot-scope="scope">
                <el-input v-model="scope.row.paramDescription" />
              </template>
            </el-table-column>
            <el-table-column>
              <template slot="header">排序号</template>
              <template slot-scope="scope">
                <el-input v-model="scope.row.orderNo" />
              </template>
            </el-table-column>
            <el-table-column label="操作" width="50">
              <template slot-scope="scope">
                <i class="delete el-icon-delete" @click="removeParam(scope.$index)" />
              </template>
            </el-table-column>
          </el-table>
        </div>

      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button v-show="saveButtonVisible" type="primary" @click="save">保存</el-button>
      <el-button @click="close">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { detailMixin } from '@/mixin/detailMixin'
const MODULE_CODE = 'scheduler'
const ENTITY_TYPE = 'job'
export default {
  name: ENTITY_TYPE + '-detail',
  mixins: [detailMixin],
  data() {
    return {
      entityType: ENTITY_TYPE,
      moduleCode: MODULE_CODE,
      // eslint-disable-next-line no-eval
      api: eval('this.$api.' + MODULE_CODE + '.' + ENTITY_TYPE),
      pageCode: MODULE_CODE + ':' + ENTITY_TYPE + ':',
      entityData: {
        paramList: []
      },
      rules: {
        name: [
          { required: true, message: '请输入名称', trigger: 'blur' }
        ],
        jobClass: [
          { required: true, message: '请输入类名', trigger: 'blur' }
        ]
      },
      currentRow: {}
    }
  },
  methods: {
    // 参数相关处理
    addParam() {
      this.entityData.paramList.push({ paramCode: '', paramValue: '', paramDescription: '' })
    },
    removeParam(index) {
      this.entityData.paramList.splice(index, 1)
    }
  }

}
</script>

<style lang="scss">
</style>
